<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="referrer" content="never">
    <script src="../js/common.js"></script>
    <script src="../../application/vue.js"></script>
    <script src="../../application/jquery.js"></script>
    <link rel="stylesheet" href="../css/base.css">
    <link rel="import" href="../vue-component/navBar.html">
    <!-- <link rel="import" href="../vue-component/film_item.html"> -->
    <link rel="import" href="../vue-component/film_list.html">
    <title>电影首页</title>
    <script>
        Vue.component("navBar", navBar);
        // Vue.component("filmItem", filmItem);
    </script>
    <script>
        window.onload = function () {
            new Vue({
                el: ".app",
                components:{
                    filmList
                },
                data:{
                   films:[]
                },
                methods:{
                    loadFilmSort(){
                        $.ajax({
                            url:"http://localhost/filmApi/loadTyps.php",
                            dataType:"json",
                            success:({result})=>{
                                this.films=result;
                                // this.getFilmById();
                                for(let i in result){
                                    this.getFilmById(result[i].typeId,i)
                                }
                            }
                        })
                    },
                    getFilmById(typeId,i){
                        $.ajax({
                            url:"http://localhost/filmApi/loadFilms.php",
                            data:{
                                typeId
                            },
                            dataType:"json",
                            success:({result})=>{
                                // console.log(result);
                                // this.films[i].list=result;
                                this.$set(this.films[i],"list",result);
                            }
                        })
                    }
                },
                mounted(){
                    this.loadFilmSort();
                    // console.log(this);
                }
            })
        }
    </script>
</head>

<body>
    <!-- 项目容器 -->
    <div class="app">
        <!-- 导航栏--搜索框 -->
        <nav-bar></nav-bar>
        <!-- 首页分类 -->
        <div class="content-box">
            <!-- 电影展示组件 -->
            <div class="home-box">
                <div v-for="(value,key) in films" :key="value.typeId">
                    <div class="list-name">
                        <span>{{value.typeName}}</span>
                        <span class="list-more">更多 > </span>
                    </div>
                    <film-list class="list-content" :list="value.list"></film-list>                  
                </div>
            </div>
        </div>
    </div>
</body>

</html>